{include file="public/header"/}
{load href="/public/static/Content/ThemesBusiness/FormPage.css"}

<div id="tabState" class="easyui-tabs" fit="true">
    <div title="新建">
        <form id="formState">
            <table class="form_table" style="width:860px">
                <tr class="form_tr">
                    <th style="padding-left:8px;" class="form_td form_th_title">
                        上传图片
                    </th>
                    <td>
                        <div id="form_ProductImg_UploadPanel">
                            <input type="file" id="file_img" accept="image/*" multiple="multiple">
                        </div>
                    </td>
                </tr>

                <tr class="form_tr">
                    <th style="padding-left:8px;width:80px;" class="form_td form_th_title">
                        排序
                    </th>
                    <td style="width:90%;padding-left:8px;" colspan="4" class="form_td form_td_content">
                        <input id="sort" name="sort" value="{$info.sort}" class="easyui-validatebox" type="number" style="width:98%;"
                            data-options="required:true,tipPosition:'right'," />
                    </td>
                </tr>

                <tr class="form_tr">
                    <td class="form_button_panel" colspan="6" style="padding-right:8px">
                        <!--  <span style="color:red;">数量限制设为0时表示不限制数量</span>  --> <a id="save"
                            class="easyui-linkbutton form-toolbar-button" data-options="iconCls:'icon-save'">保存</a>
                    </td>
                </tr>
            </table>
            <input type="hidden" name="img" id="img" value="{$info.img}">
            <input type="hidden" name="id" value="{$info.id}">
        </form>
    </div>
</div>
<script>
    document.getElementById("file_img").addEventListener("change", function (e) {
        var formData = new FormData();
        for (let index = 0; index < document.getElementById('file_img').files.length; index++) {
            formData.append('file', document.getElementById('file_img').files[index]);
            $.ajax({
                url: '/api/upload/uploads.html?path=banner',
                dataType: 'json',
                type: 'POST',
                async: false,
                data: formData,
                processData: false, // 使数据不做处理
                contentType: false, // 不要设置Content-Type请求头
                success: function (res) {
                    console.log(res.img);
                    if (res.status == 1) {
                        $('#img').val(res.info)
                    } else {
                        $.messager.alert('提示', res.msg, 'error');
                    }

                },
                error: function (response) {
                    $.messager.alert('提示', '接口错误', 'error');
                }
            });
        }
        $.messager.alert('提示', '上传成功', 'ok');
    });

    $(function () {
        $("#save").on("click", function () {
            $.ajax({
                type: 'POST',
                url: "save.html",
                data: $("#formState").serialize(),
                dataType: "json",
                async: false,
                error: function (request) {
                    alert("发送请求失败！");
                },
                success: function (data) {
                    if (data.status == 1) {
                        closeRefreshDialog();
                        //closeDialog();
                    } else {
                        // $.messager.alert('提示', data.msg, 'info');
                        // return;
                        alert(data.msg);
                    }

                }
            });
        })
    })


</script>

{include file="public/footer"/}